package com.zzy.controller;

import com.zzy.domain.dto.WarehousePageDto;
import com.zzy.domain.Result;
import com.zzy.domain.po.Warehouse;
import com.zzy.service.WarehouseService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/warehouse")
public class WarehouseController {
    private final WarehouseService warehouseService;
    /**
     * 分页查询
     */
    @GetMapping("/page")
    public Result page(WarehousePageDto dto) {
        return Result.success(warehouseService.getpage(dto));
    }
    /**
     * 新增方法
     */
    @PostMapping("/add")
    public Result add(@RequestBody Warehouse warehouse){
        warehouse.setCreateTime(LocalDateTime.now());
        warehouseService.save(warehouse);
        return Result.success( );
    }
    /**
     * 删除方法
     * 批量删除
     */
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Long>ids){
        return Result.success(warehouseService.delByIds(ids));
    }
    /**
     * 编辑功能
     */
    @PutMapping("/upbydate")
    public Result update(@RequestBody Warehouse warehouse){
        return Result.success(warehouseService.updateById(warehouse));
    }
    /**
     * 回显功能
     */
    @GetMapping("/{id}")
    public Result showid(@PathVariable Integer id){
        return Result.success(warehouseService.getById(id));
    }

    /**
     * 单个删除
     */
//    @DeleteMapping("/remove/{ids}")
//    public Result delete(@PathVariable("ids")Integer ids){
//        return Result.success(warehouseService.removeById(ids));
//    }




}
